<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="聘用岗位" prop="pinyonggangwei">
        <el-input
          v-model="queryParams.pinyonggangwei"
          placeholder="请输入聘用岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试日期">
        <el-date-picker
          v-model="daterangeMsrq"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hrmanagement:qpglqpms:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hrmanagement:qpglqpms:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hrmanagement:qpglqpms:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hrmanagement:qpglqpms:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="qpglqpmsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="应聘者姓名" align="center" prop="yingpinzhexingming" />
      <el-table-column label="性别" align="center" prop="xingbie" />
      <el-table-column label="文化程度" align="center" prop="wenhuachengdu" />
      <el-table-column label="民族" align="center" prop="minzu" />
    
      <el-table-column label="参加工作时间" align="center" prop="canjiagongzuoshijian" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.canjiagongzuoshijian, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="专业技术职称及任职时间" align="center" prop="zhuanyejishuzhichengjirenzhishijian" /> -->
      <el-table-column label="原工作单位" align="center" prop="yuangongzuodanwei" />
      <el-table-column label="家庭详细地址" align="center" prop="jiatingxiangxidizhi" />
      <el-table-column label="本人户口所在地" align="center" prop="benrenhukousuozaidi" />
      <el-table-column label="面试日期" align="center" prop="msrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.msrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hrmanagement:qpglqpms:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hrmanagement:qpglqpms:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改hrmanagement对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
    
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="招聘联系人" prop="zhaopinfuzeren" label-width="120px">
            <UserSelect ref="userselect"    :open="userOpen" @cancel="userOpen=false" :type="'multiple'" @submit="submituser"></UserSelect>
<el-select v-model="form.zhaopinfuzeren" ref="elSelect" class="hide-popper" multiple  placeholder="请选择" @focus="useropen"  >
    <el-option
    placeholder="请选择招聘联系人"
      v-for="item in useroptions"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>



        </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="联系电话" prop="shoujihao" label-width="120px">
          <el-input v-model="form.shoujihao" placeholder="请输入手机号" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="面试日期" prop="msrq" label-width="120px">
          <el-date-picker clearable
            v-model="form.msrq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择面试日期">
          </el-date-picker>
        </el-form-item>
   
</el-col>

<el-col :span="12">
  <el-form-item label="邀请评委" prop="yaoqingpingwei" label-width="120px">
    <UserSelect2  :open="userOpen2" @cancel="userOpen2=false" :type="'multiple'"  @submit2="submituser2"></UserSelect2>
<el-select  v-model="form.yaoqingpingwei" ref="elSelect2" multiple placeholder="请输入邀请评委" @focus="useropentwo">
    <el-option
    placeholder="请选择招聘联系人"
      v-for="item in useroptions"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>

        </el-form-item>
</el-col>
<el-col :span="24">
  <el-divider>应聘者信息</el-divider>

</el-col>
<el-col :span="12">
  <el-form-item label="应聘者姓名" prop="yingpinzhexingming" label-width="120px">
          <el-input v-model="form.yingpinzhexingming" placeholder="请输入应聘者姓名" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="性别" prop="xingbie" label-width="120px">
    <el-select v-model="form.xingbie" placeholder="请输入性别">
          <el-option
            v-for="dict in dict.type.sys_user_xb"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="出生年月" prop="ny" label-width="120px">
          <el-date-picker clearable
            v-model="form.ny"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生年月">
          </el-date-picker>
        </el-form-item>
</el-col>

<el-col :span="12">
        
  <el-form-item label="文化程度" prop="wenhuachengdu" label-width="120px">
    <el-select
                  v-model="form.wenhuachengdu"
                  placeholder="请输入请输入文化程度"
                >
                  <el-option
                    v-for="dict in dict.type.sys_user_qrzxl"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    placeholder="请输入文化程度"
                  ></el-option>
                </el-select>
        </el-form-item>
       

</el-col>

<el-col :span="12">
  <el-form-item label="民族" prop="minzu" label-width="120px">
          <el-input v-model="form.minzu" placeholder="请输入民族" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="入党时间" prop="rudangnianyue" label-width="120px">
          <el-date-picker clearable
            v-model="form.rudangnianyue"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入党">
          </el-date-picker>
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="参加工作时间" prop="canjiagongzuoshijian" label-width="120px">
          <el-date-picker clearable
            v-model="form.canjiagongzuoshijian"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择参加工作时间">
          </el-date-picker>
        </el-form-item>
</el-col>



<el-col :span="12">
  <el-form-item label="身份证号码" prop="shenfenzhenghaoma" label-width="120px">
          <el-input v-model="form.shenfenzhenghaoma" placeholder="请输入身份证号码" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="原工作单位" prop="yuangongzuodanwei" label-width="120px">
          <el-input v-model="form.yuangongzuodanwei" placeholder="请输入原工作单位" />
        </el-form-item>
</el-col>
<el-col :span="12">
  <el-form-item label="家庭详细地址" prop="jiatingxiangxidizhi" label-width="120px">
          <el-input v-model="form.jiatingxiangxidizhi" placeholder="请输入家庭详细地址" />
        </el-form-item>

</el-col>
<el-col :span="12">
  <el-form-item label="专业技术职称及任职时间" prop="zhuanyejishuzhichengjirenzhishijian" label-width="120px">
          <el-input v-model="form.zhuanyejishuzhichengjirenzhishijian" placeholder="请输入专业技术职称及任职时间" />
        </el-form-item>
 
</el-col>



<el-col :span="12">
  <el-form-item label="何时何院校何专业毕业" prop="heshiheyuanxiaojezhuanyebiye" label-width="120px">
          <el-input v-model="form.heshiheyuanxiaojezhuanyebiye" placeholder="请输入何时何院校何专业毕业" />
        </el-form-item>
</el-col>
<el-col :span="12">
  <el-form-item label="本人户口所在地" prop="benrenhukousuozaidi" label-width="120px">
          <el-input v-model="form.benrenhukousuozaidi" placeholder="请输入本人户口所在地" />
        </el-form-item>
</el-col>

<el-col :span="12">
     
  <el-form-item label="聘用岗位" prop="pinyonggangwei" label-width="120px">
          <el-input v-model="form.pinyonggangwei" placeholder="请输入聘用岗位" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="合同签订单位" prop="laodonghetongqiandingdanwei" label-width="120px">
          <el-input v-model="form.laodonghetongqiandingdanwei" placeholder="请输入劳动合同签订单位" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="任职资格" prop="renzhizige" label-width="120px">
          <el-input v-model="form.renzhizige" type="textarea" placeholder="请输入内容" />
        </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="主要工作职责" prop="zhuyaogongzuozhize" label-width="120px">
          <el-input v-model="form.zhuyaogongzuozhize" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      
</el-col>
<el-col :span="12">
              <el-form-item
                label="简历上传"
                label-width="130px"
                prop="zuiGaoXueLiXueXiFangShi"
              >
                <el-upload
                  ref="upload"
                  :limit="10"
                  :action="upload.url"
                  :headers="upload.headers"
                  :file-list="upload.fileList"
                  :on-progress="handleFileUploadProgress"
                   :on-success="handleFileSuccess"
                  :auto-upload="true"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                 :before-remove="beforeRemove"
                >
                  <el-button slot="trigger" size="small" type="primary"
                    >选取文件</el-button
                  >

                </el-upload>

              </el-form-item>
            </el-col>
<el-col :span="24">
  <el-divider>面试后评价</el-divider>

</el-col>
<el-col :span="12">
  <el-form-item label="评委意见" prop="pingweiyijian" label-width="120px">
    <el-select
                  v-model="form.pingweiyijian"
                  placeholder="请输入评委意见"
                >
                  <el-option
                    v-for="dict in dict.type.sys_user_msyj"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    placeholder="请输入评委意见"
                  ></el-option>
                </el-select>      
                </el-form-item>
</el-col>

<el-col :span="12">
  <el-form-item label="单位意见" prop="yongrendanweiyijian" label-width="120px">
    <el-select
                  v-model="form.yongrendanweiyijian"
                  placeholder="请输入单位意见"
                >
                  <el-option
                    v-for="dict in dict.type.sys_user_msyj"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                    placeholder="请输入单位意见"
                  ></el-option>
                </el-select> 
        </el-form-item>
</el-col>

      </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listQpglqpms, getQpglqpms, delQpglqpms, addQpglqpms, updateQpglqpms } from "@/api/hrmanagement/qpglqpms";
import { deptTreeSelect } from "@/api/system/user";
import { getUserSelect } from "@/api/system/user";
import UserSelect from "@/components/PeopleSelect/index";
import UserSelect2 from "@/components/PeopleSelect2/index";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getfilelist} from "@/api/system/info";
export default {
  name: "Qpglqpms",

  dicts: [
    "sys_user_zzmm",
    "sys_user_xb",
    "sys_user_hyzk",
    "sys_user_ygxz",
    "sys_user_ygzt",
    "sys_user_rzfs",
    "sys_user_htlx",
    "sys_user_qrzxl",
    "sys_user_xw",
    "sys_user_zgxlxxfs",
    "sys_user_msyj"
  ],
  components: { UserSelect2,Treeselect ,UserSelect},
  data() {
    return {
      upload: {
        isUploading: false,
        headers: { Authorization: "Bearer " + getToken() },
        url: process.env.VUE_APP_BASE_API + "/common/upload",
        fileList: [],
      },
      useroptions:[],
      userOpen:false,
      userOpen2:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // hrmanagement表格数据
      qpglqpmsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 面试日期时间范围
      daterangeMsrq: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pinyonggangwei: null,
        msrq: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        zhaopinfuzeren: [
          { required: true, message: "招聘负责人不能为空", trigger: "blur" },
         
        ],
        shoujihao: [
            { required: true, message: '手机号不能为空', trigger: 'change' }
          ],
          msrq: [
            { required: true, message: '面试日期不能为空', trigger: 'blur' },
          ],
          yaoqingpingwei: [
            { required: true, message: '邀请评委不能为空', trigger: 'blur' },
          ],
          yingpinzhexingming: [
          { required: true, message: "应聘者姓名不能为空", trigger: "blur" },
         
        ],
        xingbie: [
            { required: true, message: '性别不能为空', trigger: 'change' }
          ],
          ny: [
            { required: true, message: '出生年月不能为空', trigger: 'blur' },
          ],
          wenhuachengdu: [
            { required: true, message: '文化程度不能为空', trigger: 'blur' },
          ],
       
      }
    };
  },
  created() {
    this.getList();
    getUserSelect().then(response => {
this.useroptions = response.data

console.log(this.useroptions);
      });
  },

  
  methods: {
    
    useropen(){
      console.log("打开选人组件");
        this.userOpen=true;
        this.$refs.elSelect.blur()

       },

       useropentwo(){
        this.$refs.elSelect2.blur()
        this.userOpen2=true;
       },


      //选择人的确定按钮事件 submitPeople(nikeNamelist)方法传参一个默认接收用户昵称数组   submitPeople(peopleList,nikeNamelist)方法传参两个则是接收用户昵称数组和用户账号数组
      submituser(peopleList){
      this.form.zhaopinfuzeren =peopleList
      console.log( this.form. zhaopinfuzeren);

 this.$forceUpdate()
        this.userOpen=false;
      },
      submituser2(peopleList){
      this.form. yaoqingpingwei = peopleList
      console.log( this.form. yaoqingpingwei);
      this.$forceUpdate()
        this.userOpen2=false;
      },
      handleRemove(file, fileList) {
      console.log(file, fileList);
    },
     // 文件上传中处理
     handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
     // 文件上传成功处理
     handleFileSuccess(response, file, fileList) {
      

      if (response.code === 200) {
        this.upload.fileList.push({name: response.originalFilename ,filePath:response.filePath});

      } 
    },
    /** 查询hrmanagement列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeMsrq && '' != this.daterangeMsrq) {
        this.queryParams.params["beginMsrq"] = this.daterangeMsrq[0];
        this.queryParams.params["endMsrq"] = this.daterangeMsrq[1];
      }
      listQpglqpms(this.queryParams).then(response => {
        this.qpglqpmsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
     


    },
  
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: null,
        companyId: null,
        companyName: null,
        departId: null,
        departName: null,
        zhaopinfuzeren: null,
        zhaopinfuzerenTxt: null,
        yingpinzhexingming: null,
        shoujihao: null,
        renzhizige: null,
        zhuyaogongzuozhize: null,
        yaoqingpingwei: null,
        yaoqingpingweiTxt: null,
        pingweiyijian: null,
        pingweiyijianTxt: null,
        yongrendanweiyijian: null,
        yongrendanweiyijianTxt: null,
        xingbie: null,
        xingbieTxt: null,
        wenhuachengdu: null,
        minzu: null,
        rudangnianyue: null,
        canjiagongzuoshijian: null,
        zhuanyejishuzhichengjirenzhishijian: null,
        shenfenzhenghaoma: null,
        yuangongzuodanwei: null,
        heshiheyuanxiaojezhuanyebiye: null,
        jiatingxiangxidizhi: null,
        benrenhukousuozaidi: null,
        pinyonggangwei: null,
        wenhuachengduTxt: null,
        ny: null,
        laodonghetongqiandingdanwei: null,
        msrq: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeMsrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.upload.fileList=[]
      this.open = true;
      this.title = "添加面试计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
     
console.log(this.upload.fileList);
      this.reset();
      const id = row.id || this.ids
      getQpglqpms(id).then(response => {
        this.form = response.data;
       
        this.form.zhaopinfuzeren =  this.form.zhaopinfuzeren.split(",")
        this.form.zhaopinfuzeren =  this.form.zhaopinfuzeren.map(item => {return +item;}); 
        this.form.yaoqingpingwei = this.form.yaoqingpingwei.split(",")
        this.form.yaoqingpingwei = this.form.yaoqingpingwei.map(item => {return +item;}); 

        this.open = true;
        this.title = "修改面试计划";
        getfilelist(id,"OaQpglqpms").then((response) => {
      this.upload.fileList = response.data

    
      });
      });
    },
    /** 提交按钮 */
    submitForm() {
      console.log();
      if ( this.form.yaoqingpingwei) {
        this.form.yaoqingpingwei = this.form.yaoqingpingwei.join(",")
      }
      if ( this.form.zhaopinfuzeren) {
        this.form.zhaopinfuzeren = this.form.zhaopinfuzeren.join(",")
      }
      var commonDto = {
  form:this.form,
  Extra: JSON.stringify(this.upload.fileList)
}
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQpglqpms(commonDto).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQpglqpms(commonDto).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除hrmanagement编号为"' + ids + '"的数据项？').then(function() {
        return delQpglqpms(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hrmanagement/qpglqpms/export', {
        ...this.queryParams
      }, `qpglqpms_${new Date().getTime()}.xlsx`)
    },
    handlePreview(file) {
console.log("file");
window.location.href ="http://localhost:8085"+file.filePath

},
handleExceed(files, fileList) {
this.$message.warning(
  `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
    files.length + fileList.length
  } 个文件`
);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}？`);
},
  }
};
</script>
<style lang="scss" scoped>
.hide-popper .el-select-dropdown {
  display: none;
}
</style>